﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'FN' AND name = 'ufn_UPDMS_Using_Label_Cnt')
	BEGIN
		DROP Function ufn_UPDMS_Using_Label_Cnt
	END
GO

SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO
/******************************************************************************
**	Name : ufn_UPDMS_Using_Label_Cnt
**	Desc : 사용중인 라벨의 갯수 리턴
**	Test Exec Query : Exec ufn_UPDMS_Using_Label_Cnt 19
**	Called by : 전체
**	Program ID : 전체
**	Auth : 송시명
**	Date : 2011-02-28
*******************************************************************************
**	Change History
*******************************************************************************
**	Date:		Author:		Description:
**	--------	--------	---------------------------------------
**	
*******************************************************************************/
CREATE FUNCTION [dbo].[ufn_UPDMS_Using_Label_Cnt]
(
@li_label_id int
)
RETURNS int
AS

BEGIN
    DECLARE @rtn as int
    SET @rtn = 0
	
    SELECT @rtn = COUNT(1)
      FROM UPDMS_COM_PGM_LABEL WITH(NOLOCK)
     WHERE Label_Id = @li_label_id

    SELECT @rtn += COUNT(1)
	  FROM UPDMS_COM_PGM_GRID_COLUMN WITH(NOLOCK)
     WHERE Label_Id = @li_label_id

    RETURN @rtn
END